package com.itheima.mapper;

import com.itheima.pojo.Menu;
import com.itheima.pojo.Permission;
import com.itheima.pojo.Role;
import com.itheima.pojo.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.HashSet;
import java.util.LinkedHashSet;

@Mapper
public interface UserMapper {
    /**
     * 通过用户名查找用户
     * @param username
     * @return
     */
    @Select("select * from t_user where username = #{username}")
    User FindByName(String username);
    /**
     * 查找用户角色
     * @param id
     * @return
     */
    @Select("select id, name, keyword, description from t_role left outer join t_user_role tur on t_role.id = tur.role_id where  tur.user_id = #{id}")
    HashSet<Role> findByid(Integer id);

    /**
     * 获取权限集
     * @param id
     * @return
     */
    @Select("select id, name, keyword, description from t_permission left join t_role_permission trp on t_permission.id = trp.permission_id where trp.role_id =#{id} ")
    HashSet<Permission> FindPermissionsById(Integer id);

    /**
     * 获取菜单集
     * @param id
     * @return
     */
    @Select("select id, name, linkUrl, path, priority, icon, description, parentMenuId, level from t_menu left join t_role_menu trm on t_menu.id = trm.menu_id   where trm.role_id =#{id}")
    LinkedHashSet<Menu> findMenusById(Integer id);
}
